package com.ruoyi.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.manage.domain.BadEvent;
import com.ruoyi.manage.service.IBadEventService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 不良事件字典Controller
 * 
 * @author liuyangyang
 * @date 2025-05-29
 */
@RestController
@RequestMapping("/manage/badevent")
public class BadEventController extends BaseController
{
    @Autowired
    private IBadEventService badEventService;

    /**
     * 查询不良事件字典列表
     */
    @PreAuthorize("@ss.hasPermi('manage:badevent:list')")
    @GetMapping("/list")
    public AjaxResult list(BadEvent badEvent)
    {
        List<BadEvent> list = badEventService.selectBadEventList(badEvent);
        return success(list);
    }

    /**
     * 导出不良事件字典列表
     */
    @PreAuthorize("@ss.hasPermi('manage:badevent:export')")
    @Log(title = "不良事件字典", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BadEvent badEvent)
    {
        List<BadEvent> list = badEventService.selectBadEventList(badEvent);
        ExcelUtil<BadEvent> util = new ExcelUtil<BadEvent>(BadEvent.class);
        util.exportExcel(response, list, "不良事件字典数据");
    }

    /**
     * 获取不良事件字典详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:badevent:query')")
    @GetMapping(value = "/{badId}")
    public AjaxResult getInfo(@PathVariable("badId") Long badId)
    {
        return success(badEventService.selectBadEventByBadId(badId));
    }

    /**
     * 新增不良事件字典
     */
    @PreAuthorize("@ss.hasPermi('manage:badevent:add')")
    @Log(title = "不良事件字典", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BadEvent badEvent)
    {
        return toAjax(badEventService.insertBadEvent(badEvent));
    }

    /**
     * 修改不良事件字典
     */
    @PreAuthorize("@ss.hasPermi('manage:badevent:edit')")
    @Log(title = "不良事件字典", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BadEvent badEvent)
    {
        return toAjax(badEventService.updateBadEvent(badEvent));
    }

    /**
     * 删除不良事件字典
     */
    @PreAuthorize("@ss.hasPermi('manage:badevent:remove')")
    @Log(title = "不良事件字典", businessType = BusinessType.DELETE)
	@DeleteMapping("/{badIds}")
    public AjaxResult remove(@PathVariable Long[] badIds)
    {
        return toAjax(badEventService.deleteBadEventByBadIds(badIds));
    }
}
